<!--
tabs-item: lab: tab显示字段; badge: 标记
-->
<template>
  <div class="m-tabs">
    <ul class="m-tabs__item">
      <li
        v-for="(item, index) in tabsArr"
        :key="'k' + index"
        class="tabs-item"
        :class="{ active: index === tabsActiveIndex }"
        @click.stop="tabsHandle(index)"
      >
        <span class="item-font" :class="{ 'dis-btn': item.disabled }">
          <el-badge :value="item.badge" :max="99">
            {{ item.lab }}
          </el-badge>
        </span>
        <!-- <span class="item-border" /> -->
      </li>
    </ul>
    <div class="m-tabs__options">
      <slot></slot>
    </div>
  </div>
</template>
<script>
export default {
  name: 'CustomTabs',
  props: {
    activeIndex: {
      type: Number,
      default: 0,
    },
    tabsArr: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      tabsActiveIndex: null,
    };
  },
  watch: {
    activeIndex: {
      immediate: true,
      handler(val) {
        this.tabsActiveIndex = val;
      },
    },
  },
  methods: {
    tabsHandle(index) {
      if (this.tabsArr[index].disabled) {
        return;
      }
      this.tabsActiveIndex = index;
      this.$emit('returnIndex', index);
      this.$emit('return-index', index);
    },
  },
};
</script>
<style lang="less">
.m-tabs {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-around;
  border-bottom: 1px solid @cutOffRuleColor;
  .m-tabs__item {
    padding-left: 0;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex: 1;
    .tabs-item {
      font-size: 16px;
      list-style: none;
      padding: 0 26px;
      height: 54px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      box-sizing: border-box;
      border-bottom: 3px solid @fontBackgroundColor;
      .item-font {
        font-weight: @boldFontWeight;
        color: @titleTextColor;
      }

      .item-border {
        display: none;
        height: 2px;
        width: 20px;
        border-radius: 2px;
        background-color: transparent;
      }
      &.active {
        font-size: 16px;
        font-weight: 500;
        box-sizing: border-box;
        border-bottom: 3px solid @dominantHue;
        .item-font {
          font-size: 16px;
          color: @dominantHue;
        }
      }
    }
    .dis-btn {
      color: #c2c2c2 !important;
    }
    .el-badge__content.is-fixed {
      top: -5px;
      right: 7px;
    }
  }
}
</style>
